/*
 * @(#)CommonServiceImpl.java
 *
 * Copyright 2012 by ShenY BIS, All rights reserved.
 */

package com.bis.common.service.impl;

import java.util.List;

import com.bis.common.entity.SystemEntity;
import com.bis.common.service.CommonService;
import com.bis.framework.base.service.BaseService;
import com.bis.framework.entity.UserEntity;
import com.bis.framework.exception.SystemException;
import com.bis.framework.util.common.CommonSqlUtil;
import com.bis.framework.util.common.MessagesUtil;

/**
 * CommonServiceImpl
 * 
 * @author BIS 2012-12-24
 */
public class CommonServiceImpl extends BaseService implements CommonService
{

    /**
     * selectForCompany
     */
    public List<SystemEntity> selectForCompany(String flag, String xmlSelectedCompany, boolean include, String companyType)
    {
        try
        {
            String sql = CommonSqlUtil.buildCompanySelectConditon(flag, xmlSelectedCompany, include, companyType);
            if (include && "".equals(sql))
            {
                return null;
            }
            else
            {
                return commonDao.selectForCompany(sql);
            }
        }
        catch (Exception e)
        {
            logger.error("异常信息:", e);
            throw new SystemException(MessagesUtil.getMessage("system001", "default", null));
        }
    }

    /**
     * selectForUser
     */
    public List<UserEntity> selectForUser(String xmlSelectedCompany, boolean include, String org_id)
    {
        try
        {
            String sql = CommonSqlUtil.buildUserSelectConditon(xmlSelectedCompany, include, org_id);
            if (include && "".equals(sql))
            {
                return null;
            }
            else
            {
                return commonDao.selectForUser(sql);
            }
        }
        catch (Exception e)
        {
            logger.error("异常信息:", e);
            throw new SystemException(MessagesUtil.getMessage("system001", "default", null));
        }
    }

    /**
     * selectForHandleUser
     */
    public List<UserEntity> selectForHandleUser(String xmlSelectedCompany, boolean include, String org_id)
    {
        try
        {
            String sql = CommonSqlUtil.buildHandleUserSelectConditon(xmlSelectedCompany, include, org_id);
            if (include && "".equals(sql))
            {
                return null;
            }
            else
            {
                return commonDao.selectForHandleUser(sql);
            }
        }
        catch (Exception e)
        {
            logger.error("异常信息:", e);
            throw new SystemException(MessagesUtil.getMessage("system001", "default", null));
        }
    }

}
